package controleur;

import javax.swing.JFrame;

import modele.BaseDeDonnees;
import vue.Fenetre;
import vue.winNouveauTrain;

public class MainControleur {
	
	static Fenetre[] Vues;
	
	static BaseDeDonnees Modele = null;
	
	public static winNouveauTrain winNouveau = null;
	
	private static String typeChange = "";
	public static void defTypeChange(String type)	{
		typeChange = type;
	}
	public static String getTypeChange()	{
		return typeChange;
	}
	
	public static void constructeur(int numFenetres) throws Exception
	{
	   if(numFenetres == 0) {
	      throw new Exception("La valeur 0 est interdit");
	   }
		Modele = new BaseDeDonnees();
		
		Vues = new Fenetre[numFenetres];
		for(int i = 1; i <= numFenetres; i++)	{
			Vues[i - 1] = new Fenetre(Modele);
			Vues[i - 1].setSize(600, 400);
			Vues[i - 1].setLocation(40 + (80 * (i - 1)), 40 + (80 * (i - 1)));
			Vues[i - 1].setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}
		
		Modele.initialiserDonnees();
	}
	
	public static void modifierArr(String[] donnees)
	{
		winNouveau = new winNouveauTrain(donnees, "arr");
	}
	
	public static void modiTrainArr(String type, int numero, String heure, String destProv, String info, int numVoie)
	{
		TrainArrivee trainBaseArr = new TrainArrivee();
		trainBaseArr.setType(type);
		trainBaseArr.setNumero(numero);
		trainBaseArr.setHeure(heure);
		trainBaseArr.setProvenance(destProv);
		trainBaseArr.setInfo(info);
		trainBaseArr.setNumeroVoie(numVoie);
		
		Modele.ModifierTrainArr(trainBaseArr);
		winNouveau = null;
	}
	
	public static void modifierDep(String[] donnees)
	{
		winNouveau = new winNouveauTrain(donnees, "dep");
	}
	
	public static void modiTrainDep(String type, int numero, String heure, String destProv, String info, int numVoie)
	{
		TrainDepart trainBaseDep = new TrainDepart();
		trainBaseDep.setType(type);
		trainBaseDep.setNumero(numero);
		trainBaseDep.setHeure(heure);
		trainBaseDep.setDestination(destProv);
		trainBaseDep.setInfo(info);
		trainBaseDep.setNumeroVoie(numVoie);
		
		Modele.ModifierTrainDep(trainBaseDep);
		winNouveau = null;
	}
	
	public static void main(String[] args)
	{
     	try   {
   		constructeur(0);
   	}
   	catch(Exception ex)  {
   	   System.out.println(ex);
   	}
	}
}
